package com.usian.admin.rabbitmq;


import com.rabbitmq.client.Channel;
import com.usian.admin.config.RabbitMQConfig;
import com.usian.admin.service.WemediaNewsAutoScanService;
import org.apache.commons.beanutils.converters.StringArrayConverter;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class AdminMQ {

    @Autowired
    private WemediaNewsAutoScanService wemediaNewsAutoScanService;


    @RabbitListener(queues = "adminQueue")
    public void authMQ(Integer id, Message message, Channel channel) throws IOException {

        channel.basicAck(message.getMessageProperties().getContentLength(), true);
        System.out.println(message.getBody());
        //触发自动审核
        wemediaNewsAutoScanService.autoScanByMediaNewsId(id);
    }

    @RabbitListener(queues = "authQueuedelay")
    public void delay(Message message, Channel channel) throws IOException {
        String id = new String(message.getBody()) ;
        channel.basicAck(message.getMessageProperties().getContentLength(), true);
        //触发自动审核
        wemediaNewsAutoScanService.autoScanByMediaNewsId(Integer.parseInt(id));
    }


//    @RabbitListener(queues = RabbitMQConfig.QUEUE_MESSAGE)
//    @RabbitHandler
//    public void msg(@Payload Object msg){
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        System.out.println("当前时间:"+dateFormat.format(new Date()));
//        System.out.println("收到信息:"+msg);
//    }


}
